package com.etoak.stock.utils;

import org.joda.time.DateTime;



/**
 * @Author by 孙有泽
 * @Date 2024/10/15 16:18
 * @Description 练习时间的工具类
 */
public class DateTime1Util {

    public static DateTime getLastDateStock(DateTime dateTime){
         if(isWorkDay(dateTime)){
                if(dateTime.isBefore(getStartDate(dateTime))){
                    dateTime=getPreviousDate(dateTime);
                }

         }
         return null;


    }

    private static DateTime getPreviousDate(DateTime dateTime) {
        int i = dateTime.dayOfWeek().get();
        DateTime preTime=null;
        if(i==1){
            preTime= dateTime.minusDays(3);
        }else if(i==7){
            preTime= dateTime.minusDays(2);
        }else if(i==6){
            preTime= dateTime.minusDays(1);
        }
        return getDateTimeWithourSecond(preTime);
    }

    private static DateTime getDateTimeWithourSecond(DateTime preTime) {
        return preTime.withSecondOfMinute(0).withMillisOfSecond(0);

    }

    private static DateTime getStartDate(DateTime dateTime) {
        DateTime dateTime1 = dateTime.withHourOfDay(9).withMinuteOfHour(30).withSecondOfMinute(0).withMillisOfSecond(0);
        return dateTime1;
    }
    /*
     * @author 孙有泽
     * @date 2024/10/15 16:28
     * @description
     */
    private static boolean isWorkDay(DateTime dateTime) {
        int i = dateTime.dayOfWeek().get();
        return i>=1&&i<=5;
    }
}
